Add 3D coordinates supports to GeoJSON reader and writer #1150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds 3D (Z) coordinates support to GeoJSON reader and writer.
It includes a new method
setOutputDimensions
for the writer, similar to the WKT one, but which (for now ?) only accepts values 2 or 3. Support for M coordinates was left out of this PR as it is discouraged by the specification, and would require more thinking about special cases. Any M values in the coordinates being serialized are therefore ignored (like the Z values were before this PR).Considering the handling of mixed 2D/3D coordinates and NaN values isn't clearly specified, I made some decisions in that regard which are of course all open for debate:
NaN
. This behavior is different than PostGIS and OGR, which both interpret missing Z coordinates as0
:As a side note, PostGIS also converts any null value in a GeoJSON string as 0:
But OGR will instead consider it an invalid input:
NaN
Z values are never included in the coordinate array, regardless of the writer output dimension. This choice was made to facilitate interoperability and round-trips within GEOS, as parsing a GeoJSON string withnull
s will result in a ParsingError... But maybe this is something we want to change, even though it would deviate from the standard which states that thecoordinates
GeoJSON member should only contain numbers.